// Cube.cpp : Implementation of CCube

#include "stdafx.h"
#include "Cube.h"

HRESULT CCube::Init(float fOffsetX, float fOffsetY, float fRadius)
{
	m_fOffsetX = fOffsetX;
	m_fOffsetY = fOffsetY;
	m_fRadius = fRadius;
	m_wAngleY = 10.0f;
	m_wAngleX = 1.0f;
	m_wAngleZ = 5.0f;
	return S_OK;
}

// CCube
HRESULT CCube::Draw()
{
	glPushMatrix();

		glTranslatef(m_fOffsetX, m_fOffsetY, -m_fRadius);
		glRotatef(m_wAngleX, 1.0f, 0.0f, 0.0f);
		glRotatef(m_wAngleY, 0.0f, 1.0f, 0.0f);
		glRotatef(m_wAngleZ, 0.0f, 0.0f, 1.0f);

		glBegin(GL_QUAD_STRIP);
			glColor3f(1.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, 0.5f);

			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, -0.5f, 0.5f);

			glColor3f(1.0f, 1.0f, 1.0f);
			glVertex3f(0.5f, 0.5f, 0.5f);

			glColor3f(1.0f, 1.0f, 0.0f);
			glVertex3f(0.5f, -0.5f, 0.5f);

			glColor3f(0.0f, 1.0f, 1.0f);
			glVertex3f(0.5f, 0.5f, -0.5f);

			glColor3f(0.0f, 1.0f, 0.0f);
			glVertex3f(0.5f, -0.5f, -0.5f);

			glColor3f(0.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, -0.5f);

			glColor3f(0.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, -0.5f,  -0.5f);

			glColor3f(1.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, 0.5f);

			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, -0.5f, 0.5f);

		glEnd();

		glBegin(GL_QUADS);
			glColor3f(1.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, 0.5f);

			glColor3f(1.0f, 1.0f, 1.0f);
			glVertex3f(0.5f, 0.5f, 0.5f);

			glColor3f(0.0f, 1.0f, 1.0f);
			glVertex3f(0.5f, 0.5f, -0.5f);

			glColor3f(0.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, -0.5f);
		glEnd();

		glBegin(GL_QUADS);
			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, -0.5f, 0.5f);

			glColor3f(1.0f, 1.0f, 0.0f);
			glVertex3f(0.5f, -0.5f, 0.5f);

			glColor3f(0.0f, 1.0f, 0.0f);
			glVertex3f(0.5f, -0.5f, -0.5f);

			glColor3f(0.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, -0.5f,  -0.5f);
		glEnd();

	glPopMatrix();

	return S_OK;
}

HRESULT CCube::Rotate(int direction)
{
	m_wAngleX += 1.0f * direction;
	m_wAngleY += 10.0f * direction;
	m_wAngleZ += 5.0f * direction;
	return S_OK;
}

